package org.example.hw;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @version 1.0.0
 * @author: lynn
 * @description:
 * @date: 2021/7/21 21:51
 */
public class PersonComparator {

    public static class  Person{
        private int ID;
        private int age;
        private int height;

        public int getID() {
            return ID;
        }

        public void setID(int ID) {
            this.ID = ID;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        public int getHeight() {
            return height;
        }

        public void setHeight(int height) {
            this.height = height;
        }

        public Person(int ID, int age, int height) {
            this.ID = ID;
            this.age = age;
            this.height = height;
        }

        @Override
        public String toString() {
            return ID+"-"+age+"-"+height;
        }
    }

    public static void main(String[] args) {
        Person p1=new Person(1,18,165);
        Person p2=new Person(2,18,166);
        Person p3=new Person(1,16,169);
        Person p4=new Person(3,16,169);
        List<Person> list=new ArrayList<>();
        list.add(p1);list.add(p2);list.add(p3);list.add(p4);
        Collections.sort(list,((o1, o2) -> {
            return o1.height-o2.height;
        }));
        Collections.sort(list,((o1, o2) -> {
            return o1.ID-o2.ID;
        }));
        System.out.println(list);

        List<Person> list1=new ArrayList<>();
        list1.add(p1);list1.add(p2);list1.add(p3);list1.add(p4);

        list1.stream()
                .sorted(Comparator.comparing(Person::getHeight))
                .sorted(Comparator.comparing(Person::getID))
                .collect(Collectors.toList());
        System.out.println(list1);
    }
}
